package jeons.Basket.biz.impl;


import java.util.List;

import jeons.Basket.biz.BasketBiz;

import jeons.Basket.dto.BasketDTO;
import jeons.Basket.dto.ModifyDTO;
import jeons.common.util.Utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import sun.swing.BakedArrayList;

@Service
@Transactional
public class BasketBizImpl extends SqlMapClientDaoSupport implements BasketBiz{
	@Autowired SqlMapClientTemplate sqlMapClientTemplate;
	
	
	@Override
	public BasketDTO insertData(BasketDTO basketDTO) {
		sqlMapClientTemplate.update("Basket.minusData", basketDTO);
		return (BasketDTO) sqlMapClientTemplate.insert("Basket.insertData",basketDTO);
		
		
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<BasketDTO> getList(String u_id) {
		return (List<BasketDTO>) sqlMapClientTemplate.queryForList("Basket.getList",u_id);
	}


	@Override
	public BasketDTO getData(int basketno) {
		return (BasketDTO) sqlMapClientTemplate.queryForObject("Basket.getData",basketno);
	}


	@Override
	public BasketDTO getPriceSUm(Integer[] chk) {
		int del_price = 0;
		int price = 0;
		int attion = 0;
		String goods_names = null;
		BasketDTO basket = null;
		for (int i = 0; i < chk.length; i++) {
			 basket = (BasketDTO) sqlMapClientTemplate.queryForObject("Basket.getDatasum",chk[i]);
			 	int tmp = basket.getWent();
			 		if (goods_names != null) {
			 			goods_names =  goods_names+"+"+basket.getGoods_name();
					}else{
						
						goods_names =  basket.getGoods_name();
					}
					price += basket.getPrice_i()*tmp;
			 		System.out.println("i�� ȸ��� : " + i);
			 		System.out.println("���� ���� : "+tmp);
					if (basket.getAddtion_i() != null) {
						System.out.println("aaaaaaaaaaaaaaa");
						attion += basket.getAddtion_i()*tmp; 
						System.out.println("bbbbbbbbbbbb");
						System.out.println(attion);
						}
					if(basket.getDel_status().equals("sun")){ 
						System.out.println("aaaaaaaaaaaaaaa");
						System.out.println(basket.getDelivery());
						del_price += basket.getDelivery()*tmp; 
						System.out.println("ccccccccccccccccccc");
						System.out.println(del_price);
						}
		}
		System.out.println(del_price);
		System.out.println(price);
		System.out.println(attion);
		System.out.println(goods_names+"aaaaaaaaaaaaaaaaaaaaaaa");
		BasketDTO basketDTO = new BasketDTO();        
		 basketDTO.setDelivery(del_price);
		 basketDTO.setPrice_i(price);
		 basketDTO.setAddtion_i(attion);
		 basketDTO.setGoods_name(goods_names);
		return basketDTO;
	}


	@Override
	public void updateData(Integer[] chk, int dealno) {
		System.out.println("aaaa");
		for (int i = 0; i < chk.length; i++) {
			BasketDTO basketDTO = new BasketDTO();
			basketDTO.setBasketno(chk[i]);
			basketDTO.setDealno(dealno);
			sqlMapClientTemplate.update("Basket.dealData",basketDTO);
		}
		
	}


	/* (non-Javadoc)��ٱ��ϸ� ������ ������ �κа�������
	 * @see jeons.Basket.biz.BasketBiz#getCartData(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<BasketDTO> getCartData(String u_id) {
		return (List<BasketDTO>) sqlMapClientTemplate.queryForList("Basket.getCartData",u_id);
	}





	
	
}
